﻿namespace NoIdeaIoc.Logger;
/// <summary>
/// 日志信息类
/// </summary>
class InternalLogEntity
{
    /// <summary>
    /// 日志信息类
    /// </summary>
    public InternalLogEntity() { }
    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreateTime { get; set; }
    /// <summary>
    /// 线程Id
    /// </summary>
    public int ThreadID { get; set; }
    /// <summary>
    /// TaskId
    /// </summary>
    public int TaskId { get; set; }
    /// <summary>
    /// 线程名称
    /// </summary>
    public string ThreadName { get; set; }
    /// <summary>
    /// 线程类型
    /// </summary>
    public string ThreadType { get; set; }
    /// <summary>
    /// 日志信息
    /// </summary>
    public string Message { get; set; }
    /// <summary>
    /// 异常类型全名
    /// </summary>
    public string ExName { get; set; }
    /// <summary>
    /// 异常堆栈信息
    /// </summary>
    public string StackTrace { get; set; }
    /// <summary>
    /// 事件源
    /// </summary>
    public string Source { get; set; }
    /// <summary>
    /// 日志级别
    /// </summary>
    public LogLevel LogLevel { get; set; }
    /// <summary>
    /// 是否异常
    /// </summary>
    public bool IsError { get; set; }
    /// <summary>
    /// 重载
    /// </summary>
    /// <returns></returns>
    public override string ToString()
    {
        if (StackTrace != null && StackTrace.Length != 0)
            return string.Format("{0:yyyy-MM-dd HH:mm:ss.ffffff} {1} {2,3} {3} {4} {5}:{6}{7}{8}:{9}", CreateTime, Source, ThreadID, ThreadType, ThreadName, GetLevelText(LogLevel), Message, Environment.NewLine, ExName, StackTrace);
        return string.Format("{0:yyyy-MM-dd HH:mm:ss.ffffff} {1} {2,3} {3} {4} {5}:{6}", CreateTime, Source, ThreadID, ThreadType, ThreadName, GetLevelText(LogLevel), Message);
    }
    /// <summary>
    /// 根据日志等级获取提示
    /// </summary>
    /// <param name="level"></param>
    /// <returns></returns>
    static string GetLevelText(LogLevel level)
    {
        switch (level)
        {
            case LogLevel.Error:
                return "[错误]";
            case LogLevel.Critical:
                return "[致命]";
            case LogLevel.Information:
                return "[信息]";
            case LogLevel.Warning:
                return "[警告]";
            case LogLevel.Trace:
                return "[跟踪]";
            case LogLevel.None:
                return "[成功]";
            case LogLevel.Debug:
            default:
                return "[调试]";
        }
    }
}